const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});



//  一次性监听输入
function maxValue(n, v, arr) {
  const dp = new Array(v + 1).fill(0);
  for (let i = 0; i < n; i++) {
    for (let j = arr[i][0]; j <= v; j++) {
      dp[j] = Math.max(dp[j], dp[j - arr[i][0]] + arr[i][1]);
    }
  }
  return dp[v];
}

let input = [];

rl.on('line', (line) => {
  input.push(line);
})

rl.on('close', () => {
  let [n, v] = input[0].split(' ').map(Number);
  const arr = [];
  for (let i = 1; i <= n; i++) {
    arr.push([input[i].split(' ').map(Number)]);
  }

  maxValue(n,v,arr);
})